﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using Common;
using System.Configuration;

namespace ServidorDeComunicaciones
{
    class RemClient
    {
        IRemObj room;

        public RemClient() 
        {
            string RemotingServer = ConfigurationManager.AppSettings["RemotingServer"];
            IDictionary props = new Hashtable();
            props["port"] = 0;

            BinaryServerFormatterSinkProvider servProv =
                new BinaryServerFormatterSinkProvider();

            servProv.TypeFilterLevel =
                System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            TcpChannel chan = new TcpChannel(props, null, servProv);
            ChannelServices.RegisterChannel(chan, false);

            room = (IRemObj)Activator.GetObject(typeof(IRemObj),
                "tcp://" + RemotingServer + ":1234/RemObj");

            ClienteHandler cli = new ClienteHandler();
            cli.Nombre = "Comm Server";
            room.Registro(cli);
        }

        public void Enviar(string msg) 
        {
           

            room.EnviarMsg(msg);
        }
    }
}
